// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Managed Service for Apache Kafka API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_managedkafka_schemaregistry_v1::client::ManagedSchemaRegistry;
/// let client = ManagedSchemaRegistry::builder().build().await?;
/// // use `client` to make requests to the Managed Service for Apache Kafka API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// SchemaRegistry is a service that allows users to manage schemas for their
/// Kafka clusters. It provides APIs to register, list, and delete schemas, as
/// well as to get the schema for a given schema id or a given version id under a
/// subject, to update the global or subject-specific compatibility mode, and to
/// check the compatibility of a schema against a subject or a version. The main
/// resource hierarchy is as follows:
///
/// * SchemaRegistry
/// * SchemaRegistry/Context
/// * SchemaRegistry/Context/Schema
/// * SchemaRegistry/Context/Subject
/// * SchemaRegistry/Context/Subject/Version
/// * SchemaRegistry/Config
/// * SchemaRegistry/Mode
///
/// **SchemaRegistry** is the root resource to represent a schema registry
/// instance. A customer can have multiple schema registry instances in a
/// project.
///
/// **Context** is a context resource that represents a group of
/// schemas, subjects and versions. A schema registry instance can have multiple
/// contexts and always has a 'default' context. Contexts are independent of each
/// other. Context is optional and if not specified, it falls back to the
/// 'default' context.
///
/// **Schema** is a schema resource that represents a unique schema in a context
/// of a schema registry instance. Each schema has a unique schema id, and can be
/// referenced by a version of a subject.
///
/// **Subject** refers to the name under which the schema is registered. A
/// typical subject is the Kafka topic name. A schema registry instance can have
/// multiple subjects.
///
/// **Version** represents a version of a subject. A subject can have multiple
/// versions. Creation of new version of a subject is guarded by the
/// compatibility mode configured globally or for the subject specifically.
///
/// **Config** represents a config at global level cross all registry
/// instances or at subject level. Currently, only compatibility is supported in
/// config.
///
/// **Mode** represents the mode of a schema registry or a specific subject.
/// Three modes are supported:
///
/// * READONLY: The schema registry is in read-only mode, no write operations
///   allowed..
/// * READWRITE: The schema registry is in read-write mode, which allows limited
///   write operations on the schema.
/// * IMPORT: The schema registry is in import mode, which allows more editing
///   operations on the schema for data importing purposes.
///
/// # Configuration
///
/// To configure `ManagedSchemaRegistry` use the `with_*` methods in the type returned
/// by [builder()][ManagedSchemaRegistry::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://managedkafka.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::managed_schema_registry::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::managed_schema_registry::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ManagedSchemaRegistry` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `ManagedSchemaRegistry` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ManagedSchemaRegistry {
    inner: std::sync::Arc<dyn super::stub::dynamic::ManagedSchemaRegistry>,
}

impl ManagedSchemaRegistry {
    /// Returns a builder for [ManagedSchemaRegistry].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_managedkafka_schemaregistry_v1::client::ManagedSchemaRegistry;
    /// let client = ManagedSchemaRegistry::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::managed_schema_registry::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::managed_schema_registry::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ManagedSchemaRegistry + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ManagedSchemaRegistry>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ManagedSchemaRegistry> {
        super::transport::ManagedSchemaRegistry::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ManagedSchemaRegistry> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ManagedSchemaRegistry::new)
    }

    /// Get the schema registry instance.
    pub fn get_schema_registry(
        &self,
    ) -> super::builder::managed_schema_registry::GetSchemaRegistry {
        super::builder::managed_schema_registry::GetSchemaRegistry::new(self.inner.clone())
    }

    /// List schema registries.
    pub fn list_schema_registries(
        &self,
    ) -> super::builder::managed_schema_registry::ListSchemaRegistries {
        super::builder::managed_schema_registry::ListSchemaRegistries::new(self.inner.clone())
    }

    /// Create a schema registry instance.
    pub fn create_schema_registry(
        &self,
    ) -> super::builder::managed_schema_registry::CreateSchemaRegistry {
        super::builder::managed_schema_registry::CreateSchemaRegistry::new(self.inner.clone())
    }

    /// Delete a schema registry instance.
    pub fn delete_schema_registry(
        &self,
    ) -> super::builder::managed_schema_registry::DeleteSchemaRegistry {
        super::builder::managed_schema_registry::DeleteSchemaRegistry::new(self.inner.clone())
    }

    /// Get the context.
    pub fn get_context(&self) -> super::builder::managed_schema_registry::GetContext {
        super::builder::managed_schema_registry::GetContext::new(self.inner.clone())
    }

    /// List contexts for a schema registry.
    pub fn list_contexts(&self) -> super::builder::managed_schema_registry::ListContexts {
        super::builder::managed_schema_registry::ListContexts::new(self.inner.clone())
    }

    /// Get the schema for the given schema id.
    pub fn get_schema(&self) -> super::builder::managed_schema_registry::GetSchema {
        super::builder::managed_schema_registry::GetSchema::new(self.inner.clone())
    }

    /// Get the schema string for the given schema id.
    /// The response will be the schema string.
    pub fn get_raw_schema(&self) -> super::builder::managed_schema_registry::GetRawSchema {
        super::builder::managed_schema_registry::GetRawSchema::new(self.inner.clone())
    }

    /// List the schema versions for the given schema id.
    /// The response will be an array of subject-version pairs as:
    /// [{"subject":"subject1", "version":1}, {"subject":"subject2", "version":2}].
    pub fn list_schema_versions(
        &self,
    ) -> super::builder::managed_schema_registry::ListSchemaVersions {
        super::builder::managed_schema_registry::ListSchemaVersions::new(self.inner.clone())
    }

    /// List the supported schema types.
    /// The response will be an array of schema types.
    pub fn list_schema_types(&self) -> super::builder::managed_schema_registry::ListSchemaTypes {
        super::builder::managed_schema_registry::ListSchemaTypes::new(self.inner.clone())
    }

    /// List subjects in the schema registry.
    /// The response will be an array of subject names.
    pub fn list_subjects(&self) -> super::builder::managed_schema_registry::ListSubjects {
        super::builder::managed_schema_registry::ListSubjects::new(self.inner.clone())
    }

    /// List subjects which reference a particular schema id.
    /// The response will be an array of subject names.
    pub fn list_subjects_by_schema_id(
        &self,
    ) -> super::builder::managed_schema_registry::ListSubjectsBySchemaId {
        super::builder::managed_schema_registry::ListSubjectsBySchemaId::new(self.inner.clone())
    }

    /// Delete a subject.
    /// The response will be an array of versions of the deleted subject.
    pub fn delete_subject(&self) -> super::builder::managed_schema_registry::DeleteSubject {
        super::builder::managed_schema_registry::DeleteSubject::new(self.inner.clone())
    }

    /// Lookup a schema under the specified subject.
    pub fn lookup_version(&self) -> super::builder::managed_schema_registry::LookupVersion {
        super::builder::managed_schema_registry::LookupVersion::new(self.inner.clone())
    }

    /// Get a versioned schema (schema with subject/version) of a subject.
    pub fn get_version(&self) -> super::builder::managed_schema_registry::GetVersion {
        super::builder::managed_schema_registry::GetVersion::new(self.inner.clone())
    }

    /// Get the schema string only for a version of a subject.
    /// The response will be the schema string.
    pub fn get_raw_schema_version(
        &self,
    ) -> super::builder::managed_schema_registry::GetRawSchemaVersion {
        super::builder::managed_schema_registry::GetRawSchemaVersion::new(self.inner.clone())
    }

    /// Get all versions of a subject.
    /// The response will be an array of versions of the subject.
    pub fn list_versions(&self) -> super::builder::managed_schema_registry::ListVersions {
        super::builder::managed_schema_registry::ListVersions::new(self.inner.clone())
    }

    /// Register a new version under a given subject with the given schema.
    pub fn create_version(&self) -> super::builder::managed_schema_registry::CreateVersion {
        super::builder::managed_schema_registry::CreateVersion::new(self.inner.clone())
    }

    /// Delete a version of a subject.
    /// The response will be the deleted version id.
    pub fn delete_version(&self) -> super::builder::managed_schema_registry::DeleteVersion {
        super::builder::managed_schema_registry::DeleteVersion::new(self.inner.clone())
    }

    /// Get a list of IDs of schemas that reference the schema with the given
    /// subject and version.
    pub fn list_referenced_schemas(
        &self,
    ) -> super::builder::managed_schema_registry::ListReferencedSchemas {
        super::builder::managed_schema_registry::ListReferencedSchemas::new(self.inner.clone())
    }

    /// Check compatibility of a schema with all versions or a specific version of
    /// a subject.
    pub fn check_compatibility(
        &self,
    ) -> super::builder::managed_schema_registry::CheckCompatibility {
        super::builder::managed_schema_registry::CheckCompatibility::new(self.inner.clone())
    }

    /// Get schema config at global level or for a subject.
    pub fn get_schema_config(&self) -> super::builder::managed_schema_registry::GetSchemaConfig {
        super::builder::managed_schema_registry::GetSchemaConfig::new(self.inner.clone())
    }

    /// Update config at global level or for a subject.
    /// Creates a SchemaSubject-level SchemaConfig if it does not exist.
    pub fn update_schema_config(
        &self,
    ) -> super::builder::managed_schema_registry::UpdateSchemaConfig {
        super::builder::managed_schema_registry::UpdateSchemaConfig::new(self.inner.clone())
    }

    /// Delete schema config for a subject.
    pub fn delete_schema_config(
        &self,
    ) -> super::builder::managed_schema_registry::DeleteSchemaConfig {
        super::builder::managed_schema_registry::DeleteSchemaConfig::new(self.inner.clone())
    }

    /// Get mode at global level or for a subject.
    pub fn get_schema_mode(&self) -> super::builder::managed_schema_registry::GetSchemaMode {
        super::builder::managed_schema_registry::GetSchemaMode::new(self.inner.clone())
    }

    /// Update mode at global level or for a subject.
    pub fn update_schema_mode(&self) -> super::builder::managed_schema_registry::UpdateSchemaMode {
        super::builder::managed_schema_registry::UpdateSchemaMode::new(self.inner.clone())
    }

    /// Delete schema mode for a subject.
    pub fn delete_schema_mode(&self) -> super::builder::managed_schema_registry::DeleteSchemaMode {
        super::builder::managed_schema_registry::DeleteSchemaMode::new(self.inner.clone())
    }

    /// Lists information about the supported locations for this service.
    pub fn list_locations(&self) -> super::builder::managed_schema_registry::ListLocations {
        super::builder::managed_schema_registry::ListLocations::new(self.inner.clone())
    }

    /// Gets information about a location.
    pub fn get_location(&self) -> super::builder::managed_schema_registry::GetLocation {
        super::builder::managed_schema_registry::GetLocation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::managed_schema_registry::ListOperations {
        super::builder::managed_schema_registry::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::managed_schema_registry::GetOperation {
        super::builder::managed_schema_registry::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn delete_operation(&self) -> super::builder::managed_schema_registry::DeleteOperation {
        super::builder::managed_schema_registry::DeleteOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::managed_schema_registry::CancelOperation {
        super::builder::managed_schema_registry::CancelOperation::new(self.inner.clone())
    }
}
